<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新增用户</title>
	<link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
	<div class="mainBox">
		<div class="main-container">
			<div class="layui-form-item">
				<label class="layui-form-label"> 用户名 </label>
				<div class="layui-input-block">
					<input type="text" id="add_username"  lay-verify="title" autocomplete="off" placeholder="请输入用户名"
						   class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"> 密码 </label>
				<div class="layui-input-block">
					<input type="password" id="add_password"  lay-verify="title" autocomplete="off" placeholder="请输入密码"
						   class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"> 联系电话 </label>
				<div class="layui-input-block">
					<input type="text" id="add_phone" lay-verify="title" autocomplete="off" placeholder="请输入联系电话"
						   class="layui-input" >
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"> 部门编号 </label>
				<div class="layui-input-block">
					<input type="text" id="add_departid" lay-verify="title"
						   autocomplete="off" placeholder="请输入部门编号" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"> 权限管理 </label>
				<div class="layui-input-block" id ="add_auth">
					<input type="radio" name="manage" id="manage0" value="1" title="普通用户">
					<input type="radio" name="manage" id="manage1" value="1" title="管理员">
				</div>
			</div>
		</div>
	</div>
	<div class="bottom">
		<div class="button-container">
			<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
					lay-filter="task-save">
				<i class="layui-icon layui-icon-ok"></i>
				提交
			</button>
			<button type="reset" class="pear-btn pear-btn-sm">
				<i class="layui-icon layui-icon-refresh"></i>
				重置
			</button>
		</div>
	</div>
</form>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
	layui.use(['form', 'jquery'], function() {
		let form = layui.form;
		let $ = layui.jquery;
		form.on('submit(task-save)', function(data) {
			let username = $("#add_username").val()
			let password = $("#add_password").val()
			let userphone = $("#add_phone").val()
			let departmentid = $("#add_departid").val()
			let auth = $("#add_auth").val()

			$.ajax({
				url: '/user/register',
				data: JSON.stringify({
					"username":username,
					"password":password,
					"userphone":userphone,
					"departmentid":departmentid,
					"auth":auth
				}),
				dataType: 'json',
				contentType: 'application/json',
				type: 'post',
				success: function(result) {
					if (result.code === 200) {
						layer.msg(result.msg, {
							icon: 1,
							time: 1000
						}, function() {
							parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
							parent.layui.table.reload("user-table");
						});
					} else {
						layer.msg(result.msg, {
							icon: 2,
							time: 1000
						});
					}
				}
			})
			return false;
		});
	})
</script>
<script>
</script>
</body>
</html>
